Transient Model - Wizard - DialogBox

  • Step 1:

    Transient models:

    It's based on the model TransientModel class. Moreover, the data stored in the database is temporary in this class which is periodically cleared data from the database table.

    - Records in the wizard require only temporary storage, so they are deleted after some time from the database.

    - Users have all permissions on wizard records, they don't require explicit access rights.

    - Records in the wizard can refer through many2one fields or to regular records, but regular records cannot refer through many2one fields or to wizard records.

    model

    
                 class MrpProductWizard(models.TransientModel):
                    _name = 'mrp.product.produce.wizard'
                    produce_line_ids = fields.One2many('mrp.product.produce.wizard.line', 'product_produce_id',
                                                        string='Product to Track')
                    # Method to mark the mrp orders as done
                    def action_done(self):
                        for line in self.produce_line_ids.mapped('production_id'):
                            line.button_mark_done()
    
           
    
           class MrpProductProduceWizardLine(models.TransientModel):
              _name = "mrp.product.produce.wizard.line"
              _description = "Record Production Line"
              product_produce_id = fields.Many2one('mrp.product.produce.wizard')
              production_id = fields.Many2one('mrp.production')
              product_id = fields.Many2one('product.product', 'Product')
              qty = fields.Float('Quantity')
    
                        

    View

    
    
    
                        <record id="view_mrp_product_done_wizard" model="ir.ui.view">
       <field name="name">mrp.product.produce.wizard.view</field>
       <field name="model">mrp.product.produce.wizard</field>
       <field name="type">form</field>
       <field name="arch" type="xml">
           <form>
               <field name="produce_line_ids" widget="one2many_list">
                   <tree string="Mrp production lines" editable="bottom">
                       <field name="product_produce_id" invisible="1"/>
                       <field name="production_id"/>
                       <field name="product_id"/>
                       <field name="qty"/>
                   </tree>
               </field>
               <footer>
                   <button name="action_done" string="Confirm" type="object" class="oe_highlight"/>
                   <button string="Cancel" class="btn btn-default" special="cancel"/>
               </footer>
           </form>
       </field>
    </record>
    
    
                        

    wizard action

    
    
                        class MrpProduction(models.Model):
       _inherit = 'mrp.production'
       # Method for the wizard Mark as Done
       def action_done_show_wizard(self):
           production_ids = self.env['mrp.production'].browse(self._context.get('active_ids', False))
           lines = []
           for line in production_ids:
               vals = (0, 0, {
                   'production_id': line.id,
                   'product_id': line.product_id.id,
                   'qty': line.product_qty
               })
               lines.append(vals)
           return {'type': 'ir.actions.act_window',
                   'name': _('Mark as Done'),
                   'res_model': 'mrp.product.produce.wizard',
                   'target': 'new',
                   'view_id': self.env.ref('multiple_mrp_orders.view_mrp_product_done_wizard').id,
                   'view_mode': 'form',
                   'context': {'default_produce_line_ids': lines}
                   }
    
    
                  
    
                  <record id="mrp_production_done_action_server" model="ir.actions.server">
       <field name="name">Mark as Done</field>
       <field name="type">ir.actions.server</field>
       <field name="model_id" ref="mrp.model_mrp_production"/>
       <field name="binding_model_id" ref="mrp.model_mrp_production"/>
       <field name="state">code</field>
       <field name="code">
           action = model.action_done_show_wizard()
       </field>
    </record>
    
                  

    Button

    
                  <button name="action_done_show_wizard" string="Wizard" type="object" class="oe_highlight"/>